package com.pet.controller.webUser;

import com.pet.context.BaseContext;
import com.pet.dto.web.PetHelpInformationDTO;
import com.pet.dto.web.PetHelpRemarkDTO;
import com.pet.entity.PetHelpInformation;
import com.pet.result.Result;
import com.pet.service.PetHelpInformationService;
import com.pet.vo.web.PetHelpInformationVO;
import com.pet.vo.web.PetHelpRemarkVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 求助信息
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class PetHelpInformationController {

    @Autowired
    private PetHelpInformationService petHelpInformationService;

    /**
     * 添加求助信息
     * @param dto
     * @return
     */
    @PostMapping("/petHelpInformation")
    private Result insertPetHelpInformation(@RequestBody PetHelpInformationDTO dto){
        log.info("添加求助信息:{}",dto);
        petHelpInformationService.insertPetHelpInformation(dto);
        return Result.success();
    }

    /**
     * 查询求助信息
     */
    @GetMapping("/petHelpInformation")
    private Result<List<PetHelpInformationVO>> selectPetHelpInformation(){
        log.info("查询求助信息");
        return Result.success(petHelpInformationService.selectPetHelpInformation());
    }


    /**
     * 发布求助评论
     */
    @PostMapping("/petHelpRemark")
    private Result insertPetHelpRemark(@RequestBody PetHelpRemarkDTO dto){
        petHelpInformationService.insertPetHelpRemark(dto);
        return Result.success();
    }

    /**
     * 查询求助评论
     */
    @GetMapping("/petHelpRemark")
    private Result<List<PetHelpRemarkVO>> selectPetHelpRemark(@RequestParam Integer helpId){

        return Result.success(petHelpInformationService.selectPetHelpRemark(helpId));
    }

    /**
     *删除求助信息
     */
    @DeleteMapping("/petHelpInformation")
    public Result deletePetHelpInformation(@RequestParam Long id){
        log.info("删除求助信息：{}",id );
        petHelpInformationService.deletePetHelpInformation(id);
        return Result.success();
    }

    /**
     * 查询个人求助信息
     */
    @GetMapping("/petHelpInformationSelf")
    public Result<List<PetHelpInformationVO>> selectPetInfoBySelfId(@RequestParam(required = false) Integer userId){
        log.info("查询个人求助信息:{}", userId);
        List<PetHelpInformationVO> voList = petHelpInformationService.selectPetInfoBySelfId(userId);

        return Result.success(voList);
    }

    /**
     * 修改个人求助信息
     */
    @PutMapping("/petHelpInformation")
    public Result updatePetHelpInformation(@RequestBody PetHelpInformationDTO petHelpInformationDTO){
        log.info("修改个人帖子:{}",petHelpInformationDTO);
        petHelpInformationService.updatePetHelpInformation(petHelpInformationDTO);
        return Result.success();
    }

}
